package com.gtotek.tumchu.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.Toast;

import com.androidquery.callback.AjaxStatus;
import com.androidquery.callback.BitmapAjaxCallback;

import com.gtotek.tumchu.R;
import com.gtotek.tumchu.base.BaseActivity;
import com.gtotek.tumchu.base.Constans;
import com.gtotek.tumchu.customview.HelpDialog;
import com.gtotek.tumchu.dao.QuestionDao;
import com.gtotek.tumchu.util.PreferenceUtil;

public class PlayingJavActivity extends BaseActivity {

	private ImageView mImgQuestion;

	private HelpDialog mHelpDialog;

	@Override
	protected void initialize() {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_playing_jav);
		this.mImgQuestion = (ImageView) this.findViewById(R.id.img_question);

		index = PreferenceUtil.getValue(mContext, Constans.KEY_INDEX_IMAGE_JAV,
				0);

		mHelpDialog = new HelpDialog(mContext);

		super.initialize();
	}

	@Override
	protected void setType() {
		// TODO Auto-generated method stub
		type = QuestionDao.TYPE_ANH_JAV;
	}

	@Override
	protected void help() {
		// TODO Auto-generated method stub
		if (ruby > 20) {
			mHelpDialog.show();
			ruby -= 20;
			PreferenceUtil.setValue(mContext, Constans.KEY_RUBY, ruby);
			mTvRuby.setText(ruby + "");
		} else {
			Toast.makeText(mContext, "Bạn không đủ ruby !!!", Toast.LENGTH_LONG)
					.show();
		}

	}

	@Override
	protected void incrementIndex() {
		// TODO Auto-generated method stub
		mHelpDialog.setIndex(index);
		PreferenceUtil.setValue(mContext, Constans.KEY_INDEX_IMAGE_JAV, index);
		super.incrementIndex();

	}

	@Override
	protected void next() {

		super.next();

		BitmapAjaxCallback ajaxCallback = new BitmapAjaxCallback() {
			@Override
			public void async(Context context) {
				// TODO Auto-generated method stub
				super.async(context);
				mProgressBar.setVisibility(View.VISIBLE);
			}

			@Override
			protected void callback(String url, ImageView iv, Bitmap bm,
					AjaxStatus status) {
				// TODO Auto-generated method stub
				super.callback(url, iv, bm, status);
				mProgressBar.setVisibility(View.GONE);
			}
		};

		this.mAQuery
				.id(this.mImgQuestion)
				.progress(this.mProgressBar)
				.image(this.mQuestionEntity.getImage(), false, false, 0,
						R.drawable.img_question, ajaxCallback);

	}

	@Override
	protected void passQuestion() {
		// TODO Auto-generated method stub
		// pass sang activity khác
		Intent intent = new Intent(mContext, WinJavActivity.class);
		intent.putExtra(Constans.KEY_QUESTIONENTITY, mQuestionEntity);
		startActivity(intent);
	}

}
